import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPer from "vuex-persistedstate";

export default new Vuex.Store({
  state: {
    list: [],
  },
  getters: {},
  mutations: {
    add(state, val) {
      // val现在有一个图片 有一个 姓名有一个心愿 需要再加一个时间
      // {
      //   name:"",
      //   wish:"",
      //   img:""
      // }
      state.list.push({ ...val, time: new Date().toLocaleString() });
      // ...展开运算符
    },
    removeAll(state, val) {
      // state 是固定参数
      // val是要删除谁
      state.list = state.list.filter((i) => {
        return val.includes(i) == false;
      });
      //把不删的留下来
    },
  },
  actions: {},
  modules: {},
  plugins: [vuexPer()],
});
